<?php
/**
 * Created by JetBrains PhpStorm.
 * User: andrei
 * Date: 7/31/12
 * Time: 1:35 PM
 * To change this template use File | Settings | File Templates.
 */


class Db_Products_Colors extends Common {
    protected static $tableName = TAB_COLORS;
    protected static $dbFields = array(
        'id',
        'c_color_name',
        'c_color_rgb',
        'deleted'
    );

    /**
     * @var Db_Products_Colors
     */
    public $objectArray;

    public $id;
    public $c_color_name;
    public $c_color_rgb;
    public $deleted;

    function __construct($value=NULL, $fieldName=NULL) {
        parent::__construct($value, $fieldName);
    }

    /**
     * This function verify and return all colors if are used in other table
     * @return mixed
     */
    public static function getAllColors() {
        $sql = 'SELECT *, `te`.`id` AS `te_id`, `c`.`id` AS `c_id` FROM ?f AS `c`
                LEFT JOIN ?f AS `te` ON `c`.`id` = `te`.`te_color_id` AND `te`.`deleted` = 0
                WHERE `c`.`deleted` = 0 GROUP BY `c`.`id`;';

        return self::$DB->select($sql, self::$tableName, TAB_THEMES);

    }
}